<template>
  <div class="nav-wrap flex position-fixed">
    <div class="nav-box flex">
      <router-link :to="{name:'information'}"><img src="../assets/svg/logo.svg" alt=""></router-link>
      <div @click="list" class="font-box flex">
        <i class="iconfont icon-xitongcaidan" v-show="!navList"></i>
        <i class="iconfont icon-guanbi" v-show="navList"></i>
      </div>
    </div>
    <div class="nav-list position-fixed" v-show="navList">
      <div class="login-status flex">
        <div class="user-infor flex" v-if="loginStatus">
          <span><img src="../assets/svg/default-avatar.svg" alt=""></span>
          <span>{{name}}</span>
        </div>
      </div>
      <ul class="nav-menu-wrap">
        <li>
          <router-link :to="{name:'information'}">最新资讯</router-link>
        </li>
        <li>
          <router-link :to="{name:'hot'}">热门话题</router-link>
        </li>
        <li>
          <router-link :to="{name:'subscribe'}">我的订阅</router-link>
        </li>
        <li>
          <router-link :to="{name:'custom'}">定制追踪</router-link>
        </li>
      </ul>
      <div class="li-search flex" v-tap="{methods:toSearch}">
        <i class="iconfont icon-sousuo"></i>
        <span class="search">搜索</span>
      </div>
      <div class="li-status">
        <template v-if="loginStatus">
          <span v-tap="{methods:logout}">退出登录</span>
        </template>
        <template v-else>
          <router-link :to="{name:'login'}">登录</router-link>
          &nbsp;|&nbsp;
          <router-link :to="{name:'register'}">注册</router-link>
        </template>
      </div>
    </div>
  </div>

</template>

<script>
  import {mapState} from 'vuex'
  export default {
    name: 'navigation',
    data() {
      return {
        navList: false,
        show: true
      }
    },
    computed: {
      ...mapState('user', [
        'loginStatus', 'headUrl', 'name'
      ])
    },
    watch: {
      $route () {
        this.navList = false
      }
    },
    methods: {
      list() {
        this.navList = !this.navList
      },
      toSearch () {
        this.$router.push({name: 'search'})
      },
      logout () {
        this.$store.commit('user/initUserInfo')
        localStorage.removeItem('token')
        this.navList = false
      }
    }
  }
</script>
<style lang="scss">
  .nav-wrap {
    z-index: 100;
    top: 0;
    left: 0;
    width: 100%;
    flex-direction: column;
    .nav-box {
      background: #2d3137;
      justify-content: space-between;
      align-items: center;
      height: 80px;
      padding: 0 40px;
      position: relative;
      a {
        img {
          width: 240px;
          height: 64px;
        }
      }
      .font-box {
        height: 80px;
        width: 70px;
        align-items: center;
        justify-content: center;
        .icon-xitongcaidan {
          font-size: 50px;
          color: #14dab0;
        }
        .icon-guanbi {
          font-size: 40px;
          color: #14dab0;
        }
      }
    }
    .nav-list {
      top: 80px;
      width: 100%;
      height: calc(100% - 80px);
      background: #2d3137;
      .login-status {
        height: 200px;
        padding: 30px;
        justify-content: center;
        .user-infor {
          justify-content: space-around;
          align-items: center;
          span:nth-child(1) {
            width: 140px;
            height: 140px;
            border-radius: 50%;
            overflow: hidden;
            background: #F7F8FA;
            img {
              width: 100%;
              height: 100%;
            }
          }
          span:nth-child(2) {
            width: 450px;
            height: 50%;
            margin-left: 20px;
            font-size: 40px;
            display: flex;
            color: white;
            align-items: center;
          }
        }
      }
      .li-search {
        align-items: center;
        width: 160px;
        line-height: 120px;
        font-size: 35px;
        color: white;
        margin: 0 80px;
        text-align: center;
        position: relative;
        .search {
          margin-left: 20px;
          color: #636364;
        }
        .icon-sousuo {
          font-size: 50px;
          color: #14dab0;
          font-weight: 800;
        }
      }

    }
    .nav-menu-wrap {
      li {
        width: 160px;
        line-height: 120px;
        font-size: 35px;
        color: white;
        margin: 0 80px;
        text-align: center;
        position: relative;
        border-bottom: 4px solid #2d3137;
      }
      .router-link-active {
        color: #14dab0;
        border-bottom: 4px solid #14dab0;
      }
    }
    .li-status{
      margin-left:80px;
      font-size: 36px;
      color: #fff;
      margin-top:40px;
    }
  }
</style>
